package kr.zetaomicron.ultrasolitaire;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import android.util.Log;

import kr.zetaomicron.ultrasolitaire.Settings;
import kr.zetaomicron.framework.Music;
import kr.zetaomicron.framework.Sound;
import kr.zetaomicron.framework.gl.Animation;
import kr.zetaomicron.framework.gl.Font;
import kr.zetaomicron.framework.gl.Texture;
import kr.zetaomicron.framework.gl.TextureRegion;
import kr.zetaomicron.framework.impl.GLGame;

public class Assets {
    public static Texture tex_bg;
    public static TextureRegion bg_bg, bg_cardselblk, bg_cardselred, bg_space_waste, bg_space_found;
    public static TextureRegion bg_colscroll_moving, bg_colscroll_left, bg_colscroll_right, bg_colscroll_left_dis, bg_colscroll_right_dis;
    public static TextureRegion bg_colscroll_left_arrow, bg_colscroll_right_arrow, bg_colscroll_left_dis_arrow, bg_colscroll_right_dis_arrow;
    public static TextureRegion bg_game_settings;
    public static List<TextureRegion> bg_list_numbers;
    
    public static Texture tex_statusbar;
    public static TextureRegion sbar_statusbar, sbar_status_undo, sbar_status_redo, sbar_status_undo_dis, sbar_status_redo_dis;
    public static TextureRegion sbar_status_zin, sbar_status_zout, sbar_status_zin_dis, sbar_status_zout_dis;
    public static TextureRegion sbar_status_autoon, sbar_status_autooff;
    
    public static Texture tex_cards_spades, tex_cards_hearts, tex_cards_clubs, tex_cards_dias;
    public static Texture tex_cards_waterdrops, tex_cards_flames, tex_cards_bubbles, tex_cards_sprouts;
    public static Texture tex_cards_backs;
    public static List<TextureRegion> list_spades, list_hearts, list_clubs, list_dias, list_backs;
    public static List<TextureRegion> list_waterdrops, list_flames, list_bubbles, list_sprouts;
    public static TextureRegion card_frontside, card_spade_up, card_spade_leftup, card_spade_left;
    
    public static Texture tex_gameset;
    public static TextureRegion gameset_title;
    public static TextureRegion gameset_menu_suits, gameset_menu_decks, gameset_menu_ranks, gameset_menu_deal;
    public static TextureRegion gameset_lock_1, gameset_lock_2, gameset_lock_3, gameset_lock_4, gameset_lock_6, gameset_lock_8;
    public static TextureRegion gameset_en_1, gameset_en_2, gameset_en_3, gameset_en_4, gameset_en_6, gameset_en_8;
    public static TextureRegion gameset_dis_1, gameset_dis_2, gameset_dis_3, gameset_dis_4, gameset_dis_6, gameset_dis_8;
    public static TextureRegion gameset_btn_ok, gameset_btn_cancel;
    public static TextureRegion gameset_lockbox, gameset_check_yes, gameset_check_no, gameset_disabled;
    public static TextureRegion pause;    
    public static TextureRegion spring;
    public static TextureRegion castle;
    public static Animation coinAnim;
    public static Animation bobJump;
    public static Animation bobFall;
    public static TextureRegion bobHit;
    public static TextureRegion platform;
    public static Texture uiTexture;
    public static TextureRegion selChap_bg, selChap_plat, selChap_A, selChap_A_en, selChap_B, selChap_B_en;
    public static TextureRegion selChap_btn_OK, selChap_btn_back, selChap_btn_start, selChap_btn_start_white;
    public static TextureRegion selLvl_bg, selLvl_btn_lvl;
    public static TextureRegion game_btn_l, game_btn_r, game_btn_j;
    public static TextureRegion game_btn_l_push, game_btn_r_push, game_btn_j_push;
    public static TextureRegion game_opening;
    public static Font font;
    
    public static Texture dlgTexture;
    public static TextureRegion dlgDownLvl;
    
    //public static Music music;
    //public static Sound jumpSound;
    //public static Sound highJumpSound;
//    public static Sound hitSound;
//    public static Sound coinSound;
//    public static Sound clickSound;
    
    public static void load(GLGame game) {
    	tex_bg = new Texture(game, "bg.png");
    	bg_bg = new TextureRegion(tex_bg, 0, 0, 315, 180);
    	bg_cardselblk = new TextureRegion(tex_bg, 420, 0, 77, 121);
    	bg_cardselred = new TextureRegion(tex_bg, 320 + 77, 0, 77, 121);
    	bg_space_waste = new TextureRegion(tex_bg, 0, 180, 77, 121);
    	bg_space_found = new TextureRegion(tex_bg, 77, 180, 77, 121);
    	bg_colscroll_moving = new TextureRegion(tex_bg, 420, 500, 1, 9);
    	bg_colscroll_left = new TextureRegion(tex_bg, 420, 500, 20, 9);
    	bg_colscroll_right = new TextureRegion(tex_bg, 440, 500, 20, 9);
    	bg_colscroll_left_dis = new TextureRegion(tex_bg, 460, 500, 20, 9);
    	bg_colscroll_right_dis = new TextureRegion(tex_bg, 480, 500, 20, 9);
    	bg_colscroll_left_arrow = new TextureRegion(tex_bg, 420, 480, 20, 20);
    	bg_colscroll_right_arrow = new TextureRegion(tex_bg, 440, 480, 20, 20);
    	bg_colscroll_left_dis_arrow = new TextureRegion(tex_bg, 460, 480, 20, 20);
    	bg_colscroll_right_dis_arrow = new TextureRegion(tex_bg, 480, 480, 20, 20);
    	bg_game_settings = new TextureRegion(tex_bg, 5, 310 - 5, 300 + 10, 160 + 10);
    	bg_list_numbers = new ArrayList<TextureRegion>();
    	for (int i = 0; i < 10; ++i) {
    		bg_list_numbers.add(new TextureRegion(tex_bg, 160 + 10 * i, 180, 10, 15));
        }
    	bg_list_numbers.add(new TextureRegion(tex_bg, 160 + 10 * 10, 180, 15, 15));	// O mark

    	tex_statusbar = new Texture(game, "statusbar.png");
    	sbar_statusbar = new TextureRegion(tex_statusbar, 0, 475, 310, 25);
    	sbar_status_zin = new TextureRegion(tex_statusbar, 315, 20, 104, 60);
    	sbar_status_zin_dis = new TextureRegion(tex_statusbar, 315, 80, 104, 60);
    	sbar_status_zout = new TextureRegion(tex_statusbar, 315, 140, 104, 60);
    	sbar_status_zout_dis = new TextureRegion(tex_statusbar, 315, 200, 104, 60);
    	sbar_status_autoon = new TextureRegion(tex_statusbar, 210, 20, 104, 60);
    	sbar_status_autooff = new TextureRegion(tex_statusbar, 210, 80, 104, 60);
    	sbar_status_undo = new TextureRegion(tex_statusbar, 315, 260, 104, 60);
    	sbar_status_undo_dis = new TextureRegion(tex_statusbar, 315, 320, 104, 60);
    	sbar_status_redo = new TextureRegion(tex_statusbar, 315, 380, 104, 60);
    	sbar_status_redo_dis = new TextureRegion(tex_statusbar, 315, 440, 104, 60);
    	
    	tex_gameset = new Texture(game, "gamesettings.png");        
        gameset_title = new TextureRegion(tex_gameset, 0, 180, 500, 80);
        gameset_menu_suits = new TextureRegion(tex_gameset, 0, 260, 200, 60);
        gameset_menu_decks = new TextureRegion(tex_gameset, 0, 320, 200, 60);
        gameset_menu_ranks = new TextureRegion(tex_gameset, 0, 380, 200, 60);
        gameset_menu_deal = new TextureRegion(tex_gameset, 0, 440, 200, 60);
        gameset_lock_1 = new TextureRegion(tex_gameset, 0, 0, 30, 60);
        gameset_lock_2 = new TextureRegion(tex_gameset, 30, 0, 30, 60);
        gameset_lock_3 = new TextureRegion(tex_gameset, 60, 0, 30, 60);
        gameset_lock_4 = new TextureRegion(tex_gameset, 90, 0, 30, 60);
        gameset_lock_6 = new TextureRegion(tex_gameset, 120, 0, 30, 60);
        gameset_lock_8 = new TextureRegion(tex_gameset, 150, 0, 30, 60);
        gameset_en_1 = new TextureRegion(tex_gameset, 0, 60, 30, 60);
        gameset_en_2 = new TextureRegion(tex_gameset, 30, 60, 30, 60);
        gameset_en_3 = new TextureRegion(tex_gameset, 60, 60, 30, 60);
        gameset_en_4 = new TextureRegion(tex_gameset, 90, 60, 30, 60);
        gameset_en_6 = new TextureRegion(tex_gameset, 120, 60, 30, 60);
        gameset_en_8 = new TextureRegion(tex_gameset, 150, 60, 30, 60);
        gameset_dis_1 = new TextureRegion(tex_gameset, 0, 120, 30, 60);
        gameset_dis_2 = new TextureRegion(tex_gameset, 30, 120, 30, 60);
        gameset_dis_3 = new TextureRegion(tex_gameset, 60, 120, 30, 60);
        gameset_dis_4 = new TextureRegion(tex_gameset, 90, 120, 30, 60);
        gameset_dis_6 = new TextureRegion(tex_gameset, 120, 120, 30, 60);
        gameset_dis_8 = new TextureRegion(tex_gameset, 150, 120, 30, 60);
        gameset_lockbox = new TextureRegion(tex_gameset, 200, 0, 60, 60);
        gameset_check_yes = new TextureRegion(tex_gameset, 260, 60, 60, 60);
        gameset_check_no = new TextureRegion(tex_gameset, 200, 60, 60, 60);
        gameset_disabled = new TextureRegion(tex_gameset, 200, 120, 60, 60);
        gameset_btn_ok = new TextureRegion(tex_gameset, 200, 260, 300, 90);
        gameset_btn_cancel = new TextureRegion(tex_gameset, 200, 350, 300, 90);
        
//        coinAnim = new Animation(0.2f,                                 
//                                 new TextureRegion(items, 128, 32, 32, 64),
//                                 new TextureRegion(items, 160, 32, 32, 64),
//                                 new TextureRegion(items, 192, 32, 32, 64),
//                                 new TextureRegion(items, 160, 32, 32, 64));
//        
//        font = new Font(items, 224, 0, 16, 16, 20);
//        
//        uiTexture = new Texture(game, "ui.png");
//        selChap_bg = new TextureRegion(uiTexture, 0, 0, 600, 360);
//        selChap_plat = new TextureRegion(uiTexture, 0, 360, 600, 90);
//        selChap_A = new TextureRegion(uiTexture, 0, 450, 150, 200);
//        selChap_A_en = new TextureRegion(uiTexture, 0, 650, 150, 200);
//        selChap_B = new TextureRegion(uiTexture, 150, 450, 150, 200);
//        selLvl_bg = new TextureRegion(uiTexture, 600, 0, 600, 360);
//        selLvl_btn_lvl = new TextureRegion(uiTexture, 450, 450, 100, 100);
//        game_btn_l = new TextureRegion(uiTexture, 300, 600, 75, 75);
//        game_btn_r = new TextureRegion(uiTexture, 375, 600, 75, 75);
//        game_btn_j = new TextureRegion(uiTexture, 450, 600, 75, 75);
        
        tex_cards_spades = new Texture(game, "cards_spades.png");
        tex_cards_hearts = new Texture(game, "cards_hearts.png");
        tex_cards_clubs = new Texture(game, "cards_clubs.png");
        tex_cards_dias = new Texture(game, "cards_dias.png");
        tex_cards_waterdrops = new Texture(game, "cards_waterdrops.png");
        tex_cards_flames = new Texture(game, "cards_flames.png");
        tex_cards_bubbles = new Texture(game, "cards_bubbles.png");
        tex_cards_sprouts = new Texture(game, "cards_sprouts.png");
        tex_cards_backs = new Texture(game, "cards_backs.png");
        list_spades = new ArrayList<TextureRegion>();
        list_hearts = new ArrayList<TextureRegion>();
        list_clubs = new ArrayList<TextureRegion>();
        list_dias = new ArrayList<TextureRegion>();
        list_waterdrops = new ArrayList<TextureRegion>();
        list_flames = new ArrayList<TextureRegion>();
        list_bubbles = new ArrayList<TextureRegion>();
        list_sprouts = new ArrayList<TextureRegion>();
        list_backs = new ArrayList<TextureRegion>();
        for (int i = 0; i < 4; ++i) {
        	for (int j = 0; j < 6; ++j) {
        		list_spades.add(new TextureRegion(tex_cards_spades, 77 * j, 121 * i, 77, 121));
        		list_hearts.add(new TextureRegion(tex_cards_hearts, 77 * j, 121 * i, 77, 121));
        		list_clubs.add(new TextureRegion(tex_cards_clubs, 77 * j, 121 * i, 77, 121));
        		list_dias.add(new TextureRegion(tex_cards_dias, 77 * j, 121 * i, 77, 121));
        		list_waterdrops.add(new TextureRegion(tex_cards_waterdrops, 77 * j, 121 * i, 77, 121));
        		list_flames.add(new TextureRegion(tex_cards_sprouts, 77 * j, 121 * i, 77, 121));
        		list_bubbles.add(new TextureRegion(tex_cards_waterdrops, 77 * j, 121 * i, 77, 121));
        		list_sprouts.add(new TextureRegion(tex_cards_sprouts, 77 * j, 121 * i, 77, 121));
        		list_backs.add(new TextureRegion(tex_cards_backs, 77 * j, 121 * i, 77, 121));
        	}
        }
        
//        music = glGame.getAudio().newMusic("music.mp3");
//        music.setLooping(true);
//        music.setVolume(0.5f);
//        if(Settings.soundEnabled)
//            music.play();
//        jumpSound = glGame.getAudio().newSound("jump.ogg");
//        highJumpSound = glGame.getAudio().newSound("highjump.ogg");
//        hitSound = glGame.getAudio().newSound("hit.ogg");
//        coinSound = glGame.getAudio().newSound("coin.ogg");
//        clickSound = glGame.getAudio().newSound("click.ogg");
    }

    public static void reload() {
    	Log.i("[Assets]", "[reload]");
    	tex_bg.reload();
    	tex_statusbar.reload();
        tex_gameset.reload();
    	tex_cards_spades.reload();	tex_cards_hearts.reload();	tex_cards_clubs.reload();	tex_cards_dias.reload();
    	tex_cards_waterdrops.reload();	tex_cards_flames.reload();	tex_cards_bubbles.reload();	tex_cards_sprouts.reload();
    	tex_cards_backs.reload();
        //if(Settings.soundEnabled)
            //music.play();
    }

    public static void playSound(Sound sound) {
        if(Settings.soundEnabled)
            sound.play(1);
    }
}